{%extends file="base_content.html"%}

{%block name="js"%}

<script>
function changePermission(cb){
    if(cb.checked){
        var parent_id =$(cb).attr('parent_id');
        if(parent_id!=""){
            if(!document.getElementById(parent_id).checked){
                document.getElementById(parent_id).checked = true;
                changePermission(document.getElementById(parent_id));
            }
        }
    }else{
        var parent_id =$(cb).attr('parent_id');
        var id = cb.id;
        if(parent_id==""){
            $("input[parent_id='"+id+"']").each(function(){
                console.log(this);
                if(this.checked){
                    this.checked = false;
                    changePermission(this);
                }
            });
        }
    }

    $.get("index.php?c=sys_group_permission&m=change&group_id={%$smarty.request.sys_group_id%}&module_id="+cb.value+"&flag="+(cb.checked?1:0),function(r){
        if(r==1000){

        }else{
            alert("修改失败");
        }
    });
}
</script>
{%/block%}

{%block name="css"%}

<style>
.ace-thumbnails li{
    border: 0;
    margin-top: 5px;
    margin-left: 10px;
    margin-right: 10px;
    margin-bottom: 5px;
}
    .widget-box{
        background: #fcfcfc;
        border: 1px solid #bebebe;
    }
    .lbl {
        font-size: 15px;
    }

</style>
{%/block%}
{%block name="breadcrumb"%}
<li><a href="index.php?c=sys_user_group">用户组管理</a></li>
<li class="active">权限配置</li>
{%/block%}
{%block name="content"%}



    {%foreach from=$permission item=module%}

    <div class="col-sm-12 widget-box transparent" style="opacity: 1; z-index: 0;border: 1px solid #f4f4f4">
        <div class="widget-header">
            <h5 style="padding: 5px">{%$module.module_name%}</h5>

            <div class="widget-toolbar no-border">


                <a href="#" data-action="collapse">
                    <i class="icon-chevron-up"></i>
                </a>

            </div>
        </div>

        <div class="widget-body" style="padding-bottom: 20px">
            <div class="widget-main padding-6 no-padding-left no-padding-right">
                <ul class="ace-thumbnails">

                    {%foreach from=$module.page item=value%}

                    <li>



                        <div class="widget-box widget-color-blue" style="min-width: 180px">
                            <div class="widget-header">
                                <h5><label style="padding: 0;margin: 0">
                                    <input name="form-field-checkbox" class="ace ace-checkbox-2" type="checkbox"
                                           onchange="changePermission(this)" parent_id="" id="{%$value.id%}"
                                           value="{%$value.id%}" {%if $value.p!=0%}checked{%/if%} >
                                    <span class="lbl"> {%$value.module_name%}</span>
                                </label></h5>

                            </div>

                            <div class="widget-body">
                                {%if !empty($value.action)%}
                                <div class="widget-main">
                                    <ul class="list-unstyled spaced2" module="{%$value.id%}">

                                        {%foreach from=$value.action item=action%}
                                        <li>
                                            <label style="padding: 0;margin: 0">
                                                <input name="form-field-checkbox" class="ace ace-checkbox-2" type="checkbox"
                                                       onchange="changePermission(this)" parent_id="{%$value.id%}"
                                                       value="{%$action.id%}" {%if $action.p!=0%}checked{%/if%} >
                                                <span class="lbl"> {%$action.module_name%}</span>
                                            </label>
                                        </li>
                                        {%/foreach%}

                                    </ul>

                                </div>

                                {%/if%}
                            </div>

                        </div>
                    </li>

                    {%/foreach%}

                </ul>
            </div>
        </div>
    </div>
    {%/foreach%}

{%/block%}